﻿using NUnit.Framework;
using Sessionizer.Core;
using Sessionizer.Tests.Abstraction;

namespace Sessionizer.Tests.Core
{
   
    public abstract class SessionConfigurationTests : AbstractTest
    {

        [Test]
        public void CustomFactoryDeclarationWorks()
        {
            var configuration = Container.Resolve<ISessionConfigurationBuilder>()
                                         .Declare<Data, SessionsFactory>()
                                         .Build();
            using (var session = Container.Resolve<ISessionFactory>().Create(configuration))
            {
                var data = session.Get<Data>();
                Assert.AreEqual(data.A, 65536);
                using (session.Bind())
                {
                    var sessionsData = Container.Resolve<ISessions<Data>>();
                    Assert.IsTrue(ReferenceEquals(sessionsData.Instance,data));
                }
            }
        }
        private class Data
        {
            private readonly int _a;

            public Data(int a)
             {
                 _a = a;
             }

            public int A
            {
                get { return _a; }
            }
        }
        private class SessionsFactory:ISessionsFactory<Data>
        {
            public Data Create()
            {
                return new Data(65536);
            }
        }
    }
}